#Java - Code Snippets for '#Java.util.Iterator' - 3 code snippet(s) found |
|
Sample 1. Implementation of NamespaceContext | |
|
import java.util.Iterator;
import javax.xml.XMLConstants;
import javax.xml.namespace.NamespaceContext;
// Map prefixes to Namespace URIs
public class APINameSpaceContext implements NamespaceContext
{
static final String WEB_NAMESPACE = "http://schemas.microsoft.com/LiveSearch/2008/04/XML/web";
static final String API_NAMESPACE = "http://schemas.microsoft.com/LiveSearch/2008/04/XML/element";
static final String SPELL_NAMESPACE = "http://schemas.microsoft.com/LiveSearch/2008/04/XML/spell";
static final String RS_NAMESPACE = "http://schemas.microsoft.com/LiveSearch/2008/04/XML/relatedsearch";
static final String PB_NAMESPACE = "http://schemas.microsoft.com/LiveSearch/2008/04/XML/phonebook";
static final String MM_NAMESPACE = "http://schemas.microsoft.com/LiveSearch/2008/04/XML/multimedia";
static final String AD_NAMESPACE = "http://schemas.microsoft.com/LiveSearch/2008/04/XML/ads";
static final String IA_NAMESPACE = "http://schemas.microsoft.com/LiveSearch/2008/04/XML/instantanswer";
static final String NEWS_NAMESPACE = "http://schemas.microsoft.com/LiveSearch/2008/04/XML/news";
static final String ENCARTA_NAMESPACE = "http://schemas.microsoft.com/LiveSearch/2008/04/XML/encarta";
public String getNamespaceURI(String prefix)
{
if (prefix == null) throw new NullPointerException("Null prefix");
else if ("api".equals(prefix)) return API_NAMESPACE;
else if ("web".equals(prefix)) return WEB_NAMESPACE;
return XMLConstants.NULL_NS_URI;
}
// This method isn't necessary for XPath processing.
public String getPrefix(String uri)
{
throw new UnsupportedOperationException();
}
public Iterator getPrefixes(String arg0)
{
throw new UnsupportedOperationException();
}
}
|
|
Like Feedback NamespaceContext |
|
|
Sample 2. Internal Implementation of BufferedReader#lines | |
|
public Stream<String> lines() {
Iterator<String> iter = new Iterator<String>() {
String nextLine = null;
@Override
public boolean hasNext() {
if (nextLine != null) {
return true;
} else {
try {
nextLine = readLine();
return (nextLine != null);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
}
@Override
public String next() {
if (nextLine != null || hasNext()) {
String line = nextLine;
nextLine = null;
return line;
} else {
throw new NoSuchElementException();
}
}
};
return StreamSupport.stream(Spliterators.spliteratorUnknownSize(
iter, Spliterator.ORDERED | Spliterator.NONNULL), false);
}
|
|
Like Feedback Internal Implementation of BufferedReader#lines |
|
|
Sample 3. Code Sample / Example / Snippet of java.util.Iterator | |
|
public void validateRangeIterators() {
SortedRangeSet srs1 = new SortedRangeSet("1-10");
Iterator i1 = srs1.rangeIterator();
assert i1.hasNext() : "We should have one Range instance in our iterator.";
assert ((Range) i1.next()).toRepresentation().equals("1-10");
assert !i1.hasNext() : "There should be only one instance in our iterator.";
SortedRangeSet srs2 = new SortedRangeSet("1-5,8,10-15");
Iterator i2 = srs2.rangeIterator();
assert i2.hasNext() && i2.next() instanceof Range
&& i2.hasNext() && i2.next() instanceof Range
&& i2.hasNext() && i2.next() instanceof Range
&& !i2.hasNext() : "There should be exactly three Range instances in our iterator.";
SortedRangeSet srs3 = new SortedRangeSet("");
assert !srs3.iterator().hasNext() : "Iterator should be empty.";
}
|
|
Like Feedback java.util.Iterator |
|
|